<?php

namespace App\Models;

use App\Models\Traits\GoldBeanTrait;
use App\Models\Traits\HasScopeInquire;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use DateTimeInterface;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

/**
 * App\Models\GoldBean
 *
 * @property int $id
 * @property int $user_id
 * @property string|null $origin
 * @property string|null $result
 * @property string|null $beans
 * @property string|null $remark
 * @property string|null $reason
 * @property string|null $data
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @property-read \App\Models\User|null $user
 * @method static \Database\Factories\GoldBeanFactory factory(...$parameters)
 * @method static \Illuminate\Database\Eloquent\Builder|GoldBean newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|GoldBean newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|GoldBean query()
 * @method static \Illuminate\Database\Eloquent\Builder|GoldBean whereBeans($value)
 * @method static \Illuminate\Database\Eloquent\Builder|GoldBean whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|GoldBean whereData($value)
 * @method static \Illuminate\Database\Eloquent\Builder|GoldBean whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|GoldBean whereOrigin($value)
 * @method static \Illuminate\Database\Eloquent\Builder|GoldBean whereReason($value)
 * @method static \Illuminate\Database\Eloquent\Builder|GoldBean whereRemark($value)
 * @method static \Illuminate\Database\Eloquent\Builder|GoldBean whereResult($value)
 * @method static \Illuminate\Database\Eloquent\Builder|GoldBean whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|GoldBean whereUserId($value)
 * @mixin \Eloquent
 * @method static Builder|GoldBean inquire($condition = null)
 * @method static Builder|GoldBean orderGive()
 * @method static Builder|GoldBean overtimeFine()
 * @method static Builder|GoldBean resellingFee()
 * @method static Builder|GoldBean transferedIn()
 * @method static Builder|GoldBean transferedOut()
 * @property string|null $money
 * @method static Builder|GoldBean whereMoney($value)
 */
class GoldBean extends Model
{
    use HasFactory, HasScopeInquire, GoldBeanTrait;

	protected $guarded = ['id'];

	protected $casts = [
		'data' => 'json'
	];

	static array $inquireConditions = [
		'order_give' => '平台赠送',
		'transfered_in' => '转入',
		'transfered_out' => '转出',
		'overtime_fine' => '超时未付处罚',
		'reselling_fee' => '寄卖消费金豆',
		'charge_gold_beans'=> '充值金豆',
		'seckill_beans'=> '抢购消耗金豆',
		
	];

	public function scopeOrderGive(Builder $builder): Builder
	{
		return $builder->where('remark', 'order_gold_beans');
	}

	public function scopeTransferedIn(Builder $builder): Builder
	{
		return $builder->where('remark', 'transfered_in_beans');
	}

	public function scopeChargeGoldBeans(Builder $builder): Builder
	{
		return $builder->where('remark', 'charge_gold_beans');
	}

	public function scopeSeckillBeans(Builder $builder): Builder
	{
		return $builder->where('remark', 'reselling_fee_beans');
	}

	public function scopeTransferedOut(Builder $builder): Builder
	{
		return $builder->where('remark', 'transfered_out_beans');
	}

	public function scopeOvertimeFine(Builder $builder): Builder
	{
		return $builder->where('remark', 'overtime_fine_beans');
	}

	public function scopeResellingFee(Builder $builder): Builder
	{
		return $builder->where('remark', 'reselling_fee_beans');
	}

	public function user(): BelongsTo
	{
		return $this->belongsTo(User::class);
	}

	protected function serializeDate(DateTimeInterface $date): string
    {
        return $date->format('Y-m-d H:i:s');
    }
}
